package com.cxhc.system.service.governance;

import com.cxhc.common.annotation.DataSource;
import com.cxhc.common.enums.DataSourceType;
import com.cxhc.system.domain.ExchangeLog;
import com.cxhc.system.mapper.governance.GovernanceMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 参数配置 服务层实现
 *
 * @author Dhq
 */
@Service

public class GovernanceServiceImpl implements IGovernanceService {

    @Resource
    private GovernanceMapper governanceMapper;

    @Override
    public Boolean verificationUser(String idNumber) {
        Integer num = governanceMapper.verificationUser(idNumber);
        return num > 0;
    }

    @Override
    public Integer balance(String idNumber) {
        return governanceMapper.balance(idNumber);
    }

    /**
     * 积分兑换
     *
     * @param score
     * @param idNumber
     */
    @Override
    public void exchange(int score, String idNumber) {
        // 获取userId
        Integer userId = governanceMapper.userIdByIdNumber(idNumber);
        if (userId == null) {
            throw new RuntimeException("用户不存在");
        }
        governanceMapper.addExchangeLog(new ExchangeLog().setUserId(userId).setModuleName("积分兑换").setScore(-score));
    }
}
